<%@ page import="com.hc.commodity.pojo.Dept" %>
<%@ page import="com.hc.commodity.dao.impl.DeptDaoImpl" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/4/9
  Time: 12:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>添加部门表</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
</head>
<body>

<%
    request.setCharacterEncoding("utf-8");
    //1. 根据请求参数 部门id查询数据库 获取该部门信息
    String deptId = request.getParameter("deptId");
    DeptDaoImpl deptDao = new DeptDaoImpl();
    if (deptId != null && deptId.length()>0){
        Dept dept = deptDao.findById(Integer.parseInt(deptId));
        session.setAttribute("deptUpdate",dept);
    }

    //2. 用户修改后获取修改后的信息，提交至后台，在跳转至主界面
    String dname = request.getParameter("dname");
    if (dname != null && dname.length()>0){
        Dept dept = (Dept) session.getAttribute("deptUpdate");
        System.out.println(dept);
        dept.setDname(dname);
        dept.setLoc(request.getParameter("location"));
        deptDao.updateDept(dept);
        request.getRequestDispatcher("deplManage.jsp").forward(request,response);
    }
%>
<div class="container">
    <ul class="breadcrumb">
        <li><a href="#">员工管理系统</a></li>
        <li><a href="deplManage.jsp" target="mainFrame">部门管理</a></li>
        <li><a href="#">修改部门</a></li>
    </ul>
    <h3>修改部门</h3>
    <form class="form-horizontal" action="deplUpdate.jsp" method="post">
        <div class="form-group">
            <label class="col-md-2 control-label col-md-offset-2">部门号</label>
            <div class="col-md-3">
                <fieldset disabled>
                    <input type="test" class="form-control" id="disabledInput" placeholder="${sessionScope.deptUpdate.deptno}">
                </fieldset>
            </div>
        </div>
        <div class="form-group">
            <label for="dname" class="col-md-2 control-label col-md-offset-2">部门名称</label>
            <div class="col-md-3">
                <input type="test" class="form-control" id="dname" placeholder="${sessionScope.deptUpdate.dname}" name="dname">
            </div>
        </div>
        <div class="form-group">
            <label for="location" class="col-md-2 control-label col-md-offset-2">部门位置</label>
            <div class="col-md-3">
                <input type="test" class="form-control" id="location" placeholder="${sessionScope.deptUpdate.loc}" name="location">
            </div>
        </div>
        <div class="form-group">
            <input type="submit" value="确定" class="col-md-offset-5 btn btn-primary">
        </div>

    </form>
</div>
</body>
</html>
